package com.jimmy.medical.controller;

import com.jimmy.medical.entity.Message;
import com.jimmy.medical.entity.OrderExceptionData;
import com.jimmy.medical.entity.OrderExecutionRecord;
import com.jimmy.medical.entity.PhoneCall;
import com.jimmy.medical.model.AjaxResult;
import com.jimmy.medical.model.FeeInfo;
import com.jimmy.medical.model.SignInfo;
import com.jimmy.medical.service.IFlowOrderService;
import com.jimmy.medical.service.IOrderService;
import com.jimmy.medical.service.IPhysicalCheckFlowOrderService;
import com.jimmy.medical.service.ISignFlowOrderService;
import com.jimmy.medical.util.AjaxUtils;
import com.jimmy.medical.util.Func_T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;
    @Autowired
    @Qualifier("flowOrderService")
    private IFlowOrderService flowOrderService;
    @Autowired
    private ISignFlowOrderService signFlowOrderService;

    /**
     * 退号登记 - 取消订单
     *
     * @param flowOrderId
     * @param userId
     * @param cancelReason
     * @return
     */
    @RequestMapping("/cancelOrder")
    @ResponseBody
    public AjaxResult<Long> cancelOrder(final Long flowOrderId, final Long userId, final String cancelReason) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return flowOrderService.saveCancelOrder(flowOrderId, userId, cancelReason, true);
            }
        });
    }

    /**
     * 退号短信通知
     *
     * @param message
     * @return
     */
    @RequestMapping("/cancelMessageToCustomer")
    @ResponseBody
    public AjaxResult<Long> cancelMessageToCustomer(final Message message) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return orderService.saveCancelMessageFlow(message);
            }
        });
    }

    /**
     * 提交退号
     *
     * @param flowOrderId
     * @param userId
     * @return
     */
    @RequestMapping("/submitCancel")
    @ResponseBody
    public AjaxResult<String> submitCancel(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<String>() {
            @Override
            public String invoke() throws Exception {
                orderService.submitCancel(flowOrderId, userId);
                return "200";
            }
        });
    }

    /**
     * 改号登记
     *
     * @param info
     * @return
     */
    @RequestMapping("/reSign")
    @ResponseBody
    public AjaxResult<Long> reSign(final SignInfo info) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return signFlowOrderService.saveSignInfo(info, 1);
            }
        });
    }

    /**
     * 改号电话通知
     *
     * @param call
     * @return
     */
    @RequestMapping("/reSignNoticeToCustomer")
    @ResponseBody
    public AjaxResult<Long> reSignNoticeToCustomer(final PhoneCall call) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return orderService.saveResignNoticeInfo(call);
            }
        });
    }

    /**
     * 改号短信通知
     *
     * @param message
     * @return
     */
    @RequestMapping("/reSignMessageToCustomer")
    @ResponseBody
    public AjaxResult<Long> reSignMessageToCustomer(final Message message) {
        return AjaxUtils.process(new Func_T<Long>() {
            @Override
            public Long invoke() throws Exception {
                return orderService.saveReSignMessageFlow(message);
            }
        });
    }

    /**
     * 提交改号
     *
     * @param flowOrderId
     * @param userId
     * @return
     */
    @RequestMapping("/submitReSign")
    @ResponseBody
    public AjaxResult<String> submitReSign(final Long flowOrderId, final Long userId) {
        return AjaxUtils.process(new Func_T<String>() {
            @Override
            public String invoke() throws Exception {
                orderService.submitReSign(flowOrderId, userId);
                return "200";
            }
        });
    }
}
